scr= input () 
if len(scr) == 4 and scr.isdigit(): 
    scr = int(scr) 
    largest= 0 
    for i in range(4, 0, -1): 
        sub_scr = int(str(scr)[:i]) 
        is_prime = True 
        if sub_scr > 1: 
            for j in range(2,
                           int(sub_scr**0.5) + 1): 
                if sub_scr % j == 0: 
                    is_prime = False 
                    break 
            if is_prime: 
                largest = sub_scr 
                break 
    print(largest) 
else: 
    print(0)

